package br.com.novagalvao.DAO;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import br.com.novagalvao.beans.Cargo;
import br.com.novagalvao.beans.Funcionario;
import br.com.novagalvao.repositorio.CargoRepositorio;

@Repository
@Transactional
public class CargoDao implements CargoRepositorio {
	
	private SessionFactory sf;
	
	@Autowired
	public CargoDao(SessionFactory factory) {
		this.sf = factory;
	}
	
	
	private Session getSession(){
		return sf.getCurrentSession();
	}
	
	
	public void salvar(Cargo cargo) {
		getSession().save(cargo);
	}
	
	public void editar(Cargo cargo) {
		getSession().update(cargo);
	}
	

	@SuppressWarnings("unchecked")
	public List<Cargo> listAll() {
		return getSession().createCriteria(Cargo.class).list();
	}
	

	public void excluir(int id) {
		getSession().delete(getSession().load(Cargo.class, id));		
	}

	
	

	public Cargo loadById(int id) {
		return (Cargo) getSession().get(Cargo.class, id);
	}
	


}
